<?php
connect_database();

function connect_database(){
		$mysqli = new mysqli('localhost', 'root', '', 'gluphien');
		//echo $DBConnect;
		if ($mysqli->connect_errno)
			echo "<p>Connection Failed.</p>";
		//
		//	TODO: get user details add to complaint then generate refNum and add to request table
		// 
		$return = "<table>";
		$SQLstring = "SELECT * FROM `request`";
		if($result = $mysqli->query($SQLstring)){
			while(($Row = $result->fetch_row())) {
				$return .= "<tr>";
				$return .= "<td>" . $Row[0] . "</td>";
				$return .= "<td>" . $Row[1] . "</td>";
				$return .= "<td>" . $Row[2] . "</td>";
				$return .= "<td>" . $Row[3] . "</td>";
				$return .= "<td>" . $Row[4] . "</td>";
				$SQLstring = "SELECT * FROM `userdetails`";
				if($result1 = $mysqli->query($SQLstring)){
					while(($Row1 = $result1->fetch_row())) {
						if($Row[1] == $Row1[0]){
							$return .= "<td>" . $Row1[1] . "</td>";
							$return .= "<td>" . $Row1[2] . "</td>";
							$return .= "<td>" . $Row1[3] . "</td>";
							$return .= "<td>" . $Row1[4] . "</td>";
							$return .= "<td>" . $Row1[5] . "</td>";
							$return .= "<td>" . $Row1[6] . "</td>";
							$return .= "<td>" . $Row1[7] . "</td>";
							$return .= "<td>" . $Row1[8] . "</td>";
							$return .= "<td>" . $Row1[9] . "</td>";
							$return .= "<td>" . $Row1[10] . "</td>";
						}
					}
				}
				$return .= "<td><button class='email' id='". $Row[0] ."'>Send Email</button</td>";
				$return .= "<td><button class='reject' id='". $Row[0] ."'>Reject</button</td>";
				$return .= "</tr>";
			}
		}
		$return .= "</table>";
		echo $return;
		$mysqli->close();
	}
?>